package cn.kgm.user.api.factory;

import cn.kgm.core.http.response.R;
import cn.kgm.user.api.UserFeignApi;
import cn.kgm.user.dto.dto.UserSaveDTO;
import cn.kgm.user.dto.dto.UserUpdateDTO;
import cn.kgm.user.dto.query.UserPageQuery;
import cn.kgm.user.dto.vo.UserVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * # 技术改变自己 #
 * 用户基础表
 * @author kappi
 * @email yolo.jk@qq.com
 * @date  2024-04-08 13:28:48
 */
@Slf4j
@Component
public class UserFallbackFactory implements FallbackFactory<UserFeignApi> {

    @Override
    public UserFeignApi create(Throwable throwable) {
        throwable.printStackTrace();
        log.error("用户基础表服务调用失败===>{}", throwable.getMessage());
        return new UserFeignApi() {

            @Override
            public R<IPage<UserVO>> page(UserPageQuery data) {
                return R.fail("用户基础表,【page】方法调用失败===>" + throwable.getMessage());
            }

            @Override
            public R<UserVO> get(@PathVariable(value = "id") Long id) {
                return R.fail("用户基础表,【get】方法调用失败===>" + throwable.getMessage());
            }

            @Override
            public R<Boolean> save(@RequestBody @Validated UserSaveDTO data) {
                return R.fail("用户基础表,【save】方法调用失败===>" + throwable.getMessage());
            }

            @Override
            public R<Boolean> update(@RequestBody @Validated UserUpdateDTO data) {
                return R.fail("用户基础表,【update】方法调用失败===>" + throwable.getMessage());
            }

            @Override
            public R<Boolean> delete(@PathVariable(value = "ids") Long[] ids) {
                return R.fail("用户基础表,【delete】方法调用失败===>" + throwable.getMessage());
            }
        };
    }
}

